package com.sunnada.edu.system.sysrole.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;





import org.springframework.stereotype.Repository;

import com.sunnada.edu.system.pub.dao.BaseDaoImpl;



@SuppressWarnings("unchecked")
@Repository
public class RoleDaoImpl extends BaseDaoImpl implements RoleDao {

	@SuppressWarnings("rawtypes")
	@Override
	public int getRoleCots(HashMap<String, String> params) {
		List list = selectList("role_sqlmap.getRoleCots", params);
		if(list!=null&&list.size()>0){
			String cot = ((Map)list.get(0)).get("cot")+"";
			return Integer.valueOf(cot);
		}
		return 0;
	}

	@Override
	public List<?> findRoles(HashMap<String, String> params) {
		return selectList("role_sqlmap.findRoles", params);
	}

	
	@Override
	public int roleAdd(HashMap<String, String> params) {
		return insert("role_sqlmap.roleAdd",params);
	}
	@Override
	public int moduleRoleAdd(HashMap<String, String> params) {
		return insert("role_sqlmap.moduleRoleAdd", params);
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public Map getRoleByRecId(HashMap<String, String> params) {
		List list = selectList("role_sqlmap.getRoleByRecId", params);
		if(list!=null&&list.size()>0){
			return (Map)list.get(0);
		}
		return null;
	}
	
	@Override
	public int roleUpdate(HashMap<String, String> params) {
		return update("role_sqlmap.roleUpdate",params);
	}
	@Override
	public int roleDel(HashMap<String, String> params) {
		return delete("role_sqlmap.roleDel", params);
	}

	@Override
	public int moduleRoleDelete(HashMap<String, String> params) {
		return delete("role_sqlmap.moduleRoleDelete", params);
	}

	@Override
	public String[] getModuleIdsByRoleId(HashMap<String, String> params) {
		String[] s = new String[2];
		s[0]="";
		s[1]="";
		List<?> list = selectList("role_sqlmap.getModuleIdsByRoleId", params);
		if(list!=null&&list.size()>0){
			for(int i=0;i<list.size();i++){
				if(i!=0){
					s[0]+=",";
					s[1]+=",";
				}
				s[0]+=((Map)list.get(i)).get("MODULE_ID");
				s[1]+=((Map)list.get(i)).get("MODULE_NAME");
			}
		}
		return s;
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	@Override
	public List roleTree2(HashMap<String, String> params) {
		return  selectList("role_sqlmap.roleTree2", params);
	}

	@Override
	public int getRoleUserCots(HashMap<String, String> params) {
		List list = selectList("role_sqlmap.getRoleUserCots", params);
		if(list!=null&&list.size()>0){
			String cot = ((Map)list.get(0)).get("cot")+"";
			return Integer.valueOf(cot);
		}
		return 0;
	}

	@Override
	public List<?> findRoleUsers(HashMap<String, String> params) {
		return selectList("role_sqlmap.findRoleUsers", params);
	}


	@Override
	public int getUserNoexistRoleIdCots(HashMap<String, String> params) {
		List list=selectList("role_sqlmap.getUserNoexistRoleIdCots",params);
		if (list!=null&&list.size()>0) {
			String cot=((Map) list.get(0)).get("cot")+"";
			return Integer.valueOf(cot);
		}
		return 0;
	}

	@Override
	public List<?> findUserNoexistRoleIds(HashMap<String, String> params) {
		return selectList("role_sqlmap.findUserNoexistRoleIds", params);
	}

	@Override
	public int roleBindSave(HashMap<String, String> params) {
		return insert("user_sqlmap.roleUserAdd",params);
		/*insert into s_sysroleuser(REC_ID,ROLE_ID,USER_ID) 
		   values(jkmini_seq.nextval,#{roleId},#{userId})*/
	}

	@Override
	public int roleBindDelete(HashMap<String, String> params) {
		return delete("role_sqlmap.roleBindDelete", params);
	}

	@Override
	public int roleEnable(HashMap<String, String> params) {
		return update("role_sqlmap.roleEnable",params);
	}

	@Override
	public int roleDisable(HashMap<String, String> params) {
		return update("role_sqlmap.roleDisable",params);
	}

	@Override
	public List roleAuthorizeTree(HashMap<String, String> params) {
		return selectList("role_sqlmap.roleAuthorizeTree", params);
		
	}
}
